import { createRouter, createWebHashHistory } from 'vue-router'
import Index from '@/views/Index.vue'


const routes = [
  {
    path: '/',
    name: 'towIndex',
    redirect: '/towIndex', 
  },
  {
    path: '/towIndex',
    name: '二级',
    component:() => import('@/views/towIndex'),
  },
  {
    path: '/login',
    name: '登录',
    component:() => import('@/views/login'),
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next) => {
  document.title = to.meta.title || '指挥中心'; // 设置浏览器标签页标题
  if(to.path == '/login'){
    next()
  }
  if(sessionStorage.getItem('token')){

    next()
  }else{
    next({
         path: '/login'
    })
  }

});


router.beforeEach((to) => {
  document.title = to.meta.title || '指挥中心'; // 设置浏览器标签页标题
});

export default router
